import java.util.Arrays;

public class Tesk1 {
    public static void reverse(int[] nums,int left,int right){
        while (left < right){
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
            left++;
            right--;
        }

    }
    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7,8,9};
        int k = 2;
        reverse(nums,0, nums.length-1);
        reverse(nums,0,k-1);
        reverse(nums,k, nums.length-1);
        System.out.println(Arrays.toString(nums));

    }
    public static void main1(String[] args) {
        int[] nums = {1,2,3,4,5,6,7,8,9,};
        int k = 2;
        int n = nums.length;
        int[] num = Arrays.copyOf(nums,n);
        for (int i = 0; i < n; i++) {
            nums[(i+k)%n] = num[i];
        }
        System.out.println(Arrays.toString(nums));
    }
}
